//package com.doyutu.seed.controller;
//
//import com.doyutu.seed.repository.elasticsearch.SeedUserSearchRepository;
//import com.doyutu.seed.repository.elasticsearch.document.SeedUserSearchDoc;
//import org.elasticsearch.index.query.QueryBuilders;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.domain.Pageable;
//import org.springframework.data.elasticsearch.core.ElasticsearchTemplate;
//import org.springframework.data.elasticsearch.core.query.IndexQuery;
//import org.springframework.data.elasticsearch.core.query.IndexQueryBuilder;
//import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
//import org.springframework.data.elasticsearch.core.query.SearchQuery;
//import org.springframework.data.web.PageableDefault;
//import org.springframework.web.bind.annotation.GetMapping;
//import org.springframework.web.bind.annotation.PathVariable;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.RestController;
//
//import java.util.Collections;
//
///**
// * @author DoyuTu
// * @version 0.0.1
// * spring-boot-project-seed
// */
//@RestController
//@RequestMapping("search")
//public class SeedUserSearchController {
//
//    @Autowired
//    private SeedUserSearchRepository seedUserSearchRepository;
//
//    @Autowired
//    private ElasticsearchTemplate elasticsearchTemplate;
//
//    /**
//     * <p>
//     * curl -XGET http://localhost:8888/search/createSeedUserIndex/1/2/man/enabled?page=2&size=1
//     * </p>
//     */
//    @GetMapping("createSeedUserIndex/{id}/{userName}/{type}/{state}")
//    public Object createSeedUserIndex(@PathVariable String id, @PathVariable String userName, @PathVariable String type, @PathVariable String state, @PageableDefault Pageable pageable) {
//        if (!elasticsearchTemplate.indexExists(SeedUserSearchDoc.class)) {
//            elasticsearchTemplate.createIndex(SeedUserSearchDoc.class);
//        }
//        SeedUserSearchDoc searchSeedUser = new SeedUserSearchDoc(userName, type, state);
//        IndexQuery indexQuery = new IndexQueryBuilder()
//                .withId(id)
//                .withObject(searchSeedUser)
//                .build();
//        elasticsearchTemplate.bulkIndex(Collections.singletonList(indexQuery));
//        SearchQuery searchQuery = new NativeSearchQueryBuilder()
//                .withQuery(QueryBuilders.matchAllQuery())
//                .withPageable(pageable)
//                .build();
//        return elasticsearchTemplate.queryForList(searchQuery, SeedUserSearchDoc.class);
//    }
//
//    @GetMapping("getSeedUserBySearch/{userName}/{type}/{state}")
//    public Object getSeedUserBySearch(@PathVariable String userName, @PathVariable String type, @PathVariable String state) {
//        return seedUserSearchRepository.findAllByUserNameOrTypeOrState(userName, type, state);
//    }
//
//    @GetMapping("saveSeedUserBySearch/{userName}/{type}/{state}")
//    public Object saveSeedUserBySearch(@PathVariable String userName, @PathVariable String type, @PathVariable String state) {
//        SeedUserSearchDoc searchSeedUser = new SeedUserSearchDoc(userName, type, state);
//        return seedUserSearchRepository.save(searchSeedUser);
//    }
//
//}
